<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增申请记录')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-applyRecord-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">OA编号：</label>
                <div class="col-sm-8">
                    <input name="applyOaNumber" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">申请人：</label>
                <div class="col-sm-8">
                    <input name="applyName" class="form-control" type="text" onblur="getNameDepartment('applyName','proposer')">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">申请人姓名：</label>
                <div class="col-sm-8">
                    <input name="proposer" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">申请部门：</label>
                <div class="col-sm-8">
                    <input name="applyDepartment" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">申请时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="applyTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">耗材名称：</label>
                <div class="col-sm-8">
                    <input name="applyConName" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">耗材规格：</label>
                <div class="col-sm-8">
                    <input name="applyConSpecification" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">耗材数量：</label>
                <div class="col-sm-8">
                    <input name="applyConCount" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">耗材单位：</label>
                <div class="col-sm-8">
                    <input name="applyConUnit" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">使用工号：</label>
                <div class="col-sm-8">
                    <input name="userId" class="form-control" type="text" onblur="getNameDepartment('userId','user')">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">使用人：</label>
                <div class="col-sm-8">
                    <input name="user" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">使用部门：</label>
                <div class="col-sm-8">
                    <input name="department" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">领用编号：</label>
                <div class="col-sm-8">
                    <input name="receiveOaNumber" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "consumables/applyRecord"
        $("#form-applyRecord-add").validate({
            focusCleanup: true
        });

        function getNameDepartment(userId,userName) {
            // 获取工号输入框的值
            var id = document.getElementsByName(userId)[0].value;
            // 发送GET请求到后端获取参数
            $.get("http://172.20.203.11/getoanamedept", {nameid: id}, function (response) {
                var parse = JSON.parse(response);
                if (userName == "proposer" && parse.code != "1") {
                    $("input[name=proposer]").val("");
                    $("input[name=applyDepartment]").val("");
                }
                if (userName == "user" && parse.code != "1") {
                    $("input[name=user]").val("");
                    $("input[name=department]").val("");
                }
                if (parse.code == "1") {
                    // 将后端返回的参数设置给使用人输入框
                    if (userName=="proposer") {
                        $("input[name=proposer]").val(parse.name);
                        $("input[name=applyDepartment]").val(parse.parent);
                    }
                    if (userName=="user") {
                        $("input[name=user]").val(parse.name);
                        $("input[name=department]").val(parse.parent);
                    }
                }
            });
        }



        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-applyRecord-add').serialize());
            }
        }

        $("input[name='applyTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>